/**
 * 底栏仪表盘
 * "board_2018_b43"
 * 
 * @author Zdream
 * @date 2018-09-06
 * @since cgcr-0.3.0
 */

function create (context) {
	return {
		template : context.template,
		data : function () {
			return {
				chunkWidth : 372
			}
		},
		props : {
			sid : String,
		},
		methods : {
			onScreenUpdated : function () {
				let status = context.getStatus(this.sid);
				if (status.data) {
					this.chunkWidth = status.data.chunkWidth | status.data.width | 372;
				}
			},
			// 事件驱动
			chunkWidthSubmit : function () {
				context.sendCommand(this.sid, 'chunk-width', {width : this.chunkWidth});
			}
		},
		mounted : function () {
			this.onScreenUpdated(); // 更新 chunkWidth
			context.getBus().$on('screen-status-sync-all', this.onScreenUpdated);
			context.getBus().$on('screen-updated', this.onScreenUpdated);
			context.getBus().$on('screen-destroyed', this.onScreenUpdated);
		},
    destroyed : function () {
      context.getBus().$off('screen-status-sync-all', this.onScreenUpdated);
      context.getBus().$off('screen-updated', this.onScreenUpdated);
      context.getBus().$off('screen-destroyed', this.onScreenUpdated);
    }
	};
}

export default create;
